﻿using System;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using Telerik.Web.Mvc.UI;

namespace WebSite.ViewModels.Fields
{
    public class DatePickerField : FieldBase
    {
        private readonly DateTime? m_Value;
        private readonly bool m_UseValidation;

        public DatePickerField(string caption, string name, DateTime? value, bool useValidation = false)
            : base(caption, name, value)
        {
            m_Value = value;
            m_UseValidation = useValidation;
        }

        public override IHtmlString Render(HtmlHelper htmlHelper)
        {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append(htmlHelper.Telerik().DatePicker().Name(Name).Value(m_Value));
            if (m_UseValidation)
            {
                stringBuilder.Append(htmlHelper.ValidationMessage(Name));
            }
            return MvcHtmlString.Create(stringBuilder.ToString());
        }
    }
}